package com.example.babyapp;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class OtherInfoActivity extends Activity{

	
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_otherinfo);
        setOrientation();
    }

	public void gotoTestActivity(View view){
		Intent intent = new Intent(this, TestActivity.class);
		
		Intent infoIntent = getIntent();
		String[] babyInfo = infoIntent.getStringArrayExtra("babyInfo");
		String[] secondInfo = infoIntent.getStringArrayExtra("secondInfo");
		
		RadioGroup radioGroupHereditary;
		RadioButton radioButtonHereditary;
		
		RadioGroup radioGroupInfection;
		RadioButton radioButtonInfection;
		
		RadioGroup radioGroupDefect;
		RadioButton radioButtonDefect;

		radioGroupHereditary = (RadioGroup) findViewById(R.id.radioGroup1);
		int selectHereditary = radioGroupHereditary.getCheckedRadioButtonId();
		radioButtonHereditary = (RadioButton) findViewById(selectHereditary);

		radioGroupInfection = (RadioGroup) findViewById(R.id.radioGroup2);
		int selectInfection = radioGroupInfection.getCheckedRadioButtonId();
		radioButtonInfection= (RadioButton) findViewById(selectInfection);
		

		radioGroupDefect = (RadioGroup) findViewById(R.id.radioGroup3);
		int selectDefect = radioGroupDefect.getCheckedRadioButtonId();
		radioButtonDefect = (RadioButton) findViewById(selectDefect);
		
		
		if (radioButtonHereditary == null || radioButtonInfection == null ||
				radioButtonDefect == null) {
			
			Toast.makeText(getApplicationContext(), "Please Fill up All Fields", Toast.LENGTH_SHORT).show();
			
		} else if (radioButtonHereditary != null || radioButtonInfection != null ||
				radioButtonDefect != null) {
			
			String[] otherInfo = {radioButtonHereditary.getText().toString(), 
					radioButtonInfection.getText().toString(), radioButtonDefect.getText().toString() };
			
			intent.putExtra("babyInfo", babyInfo);
			intent.putExtra("secondInfo", secondInfo);
			intent.putExtra("otherInfo", otherInfo);
			
			startActivity(intent);
			
		}
		
	}
	
	protected void setOrientation() {
    	int current = getRequestedOrientation();
    	if(current != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
    		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    	}
    }

}
